package com.ang.lambda;

import java.util.concurrent.Callable;

public class Test02 {
    private Callable<String> test0(String cardNumber, String managementCode) {
        //匿名内部类创建callable对象
        Callable<String> callable = new Callable<String>() {
            @Override
            public String call() throws Exception {
                return "";
            }
        };

        return callable;
    }

    private Callable<String> test1(String cardNumber, String managementCode) {
        //lambda表达式创建callable对象
        Callable<Integer> callable = ()->{
            System.out.println("");
            return 1;
        };

        //lambda表达式创建callable对象
        Callable<String> callable1 = ()->{
            System.out.println("");
            return "";
        };

        return callable1;
    }

    private Callable<String> test2(String cardNumber, String managementCode) {
        //lambda表达式创建callable对象
        Callable<String> callable = () -> {
            try {
                return cardNumber;
            } catch (Throwable throwable) {
                return cardNumber;
            }
        };

        return callable;
    }

    private Callable<String> test3(String cardNumber, String managementCode) {
        return () -> {
            try {
                return cardNumber;
            } catch (Throwable throwable) {
                return cardNumber;
            }
        };
    }

    /**
     * 1.返回一个 Callable，Callable就一个无参方法
     *      return ()->{}
     * 2.{}里面的实现，需要返回一个泛型，所以return和Callable的泛型一样
     *      {}里面需要返回一个Long，maxNumber是Long，cardNumber是String
     *      所以返回maxNumber
     * @param cardNumber
     * @param maxNumber
     * @return
     */
    public Callable<Long> test4(String cardNumber, Long maxNumber){
        return ()->{
//            return cardNumber;
            return maxNumber;
        };
    }
}
